package 多线程.交替输出;

import 多线程.SynchronizedDemo1;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;

/**
 * @author : K k
 * @date : 21:18 2020/8/21
 */
public class ABCdemo {
    static AtomicInteger i = new AtomicInteger(1);
    static  Thread t1 = null, t2 = null, t3 = null;

    public static void main(String[] args) {
        t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int j = 0; j < 10; j++) {
                    while (i.get() != 1) {
                    }
                    System.out.println("A");
                    i.set(2);
                }
            }
        });

        t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int j = 0; j < 10; j++) {
                    while (i.get() != 2) {
                    }
                    System.out.println("B");
                    i.set(3);
                }

            }
        });

        t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int j = 0; j < 10; j++) {
                    while (i.get() != 3) {
                    }
                    System.out.println("C");
                    i.set(1);
                }

            }
        });


        t1.start();
        t2.start();
        t3.start();

    }


}
